package leetcode;

import util.Tree;
import util.TreeNode;

/**
 * @Project : AlgorithmLearning
 * @Package : Leetcode
 * @File : Q0222.java
 * @Author : WangRuoyu
 * @Date 2023/11/10 23:40
 */

public class Q0222 {
    public int countNodes(TreeNode root) {
        if (root == null) return 0;
        return countNodes(root.left) + countNodes(root.right) + 1;
    }

    public static void main(String[] args) {
        Q0222 sl = new Q0222();
        String[] nodes = {"1", "2", "4", null, null, "5", null, null, "3", "6", null, null, null};
        TreeNode root = Tree.createTreeByPreorder(nodes);
        System.out.println(sl.countNodes(root));
    }
}